import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
const layout = () => import('@/views/layout/index.vue')
const Home = () => import('@/views/Home/index.vue')
const AboutUs = () => import('@/views/AboutUs/index.vue')
const ApplyField = () => import('@/views/ApplyField/index.vue')
const ProductCenter = () => import('@/views/ProductCenter/index.vue')
const SkillSummary = () => import('@/views/SkillSummary/index.vue')
const Case = () => import('@/views/Case/index.vue')
const News = () => import('@/views/News/index.vue')
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: 'Home',
    component: layout,
    children: [
      {
        path: '/Home',
        component: Home,
        name: 'Home',
        meta: {
          title: '首页',
          keepAlive: true,
      }
    },
      {
        path: '/ApplyField',
        component: ApplyField,
        name: 'ApplyField',
        meta: {
            title: '适用领域',
            keepAlive: true,
        },
      },
      {
        path: '/AboutUs',
        component: AboutUs,
        name: 'AboutUs',
        meta: {
          title: '关于我们',
          keepAlive: false,
        },
      },
      {
        path: '/ApplyField',
        component: ApplyField,
        name: 'ApplyField',
        meta: {
          title: '适用领域',
          keepAlive: false,
        },
      },
      {
        path: '/ProductCenter',
        component: ProductCenter,
        name: 'ProductCenter',
        meta: {
          title: '产品中心',
          keepAlive: false,
        },
      },
      {
        path: '/SkillSummary',
        component: SkillSummary,
        name: 'SkillSummary',
        meta: {
          title: '技术概要',
          keepAlive: false,
        },
      },
      {
        path: '/Case',
        component: Case,
        name: 'Case',
        meta: {
          title: '实际案例',
          keepAlive: false,
        },
      },
      {
        path: '/News',
        component: News,
        name: 'News',
        meta: {
          title: '新闻中心',
          keepAlive: false,
        },
      },    ],
  },]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from) => {
  // console.log('全局路由前置守卫：to,from\n', to, from)
  // 设置页面标题
  document.title = (to.meta.title as string) || ''
  document.body.scrollTop = 0
  // firefox
  document.documentElement.scrollTop = 0
  // safari
  window.pageYOffset = 0
})

export default router;